package cn.ybk.org.controller;


import cn.ybk.basic.util.AjaxResult;
import cn.ybk.org.domain.Department;
import cn.ybk.org.service.DepartmentService;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/depart")
public class DepartmentController {

    @Autowired
    private DepartmentService departmentService;

    @GetMapping
    public List<Department> findAll() {
        return departmentService.findAll();
    }

    // 添加修改 用工具类
    @PutMapping
    public AjaxResult addOrUpdate(@RequestBody Department department){
        Long id = department.getId();
        System.err.println(id);
        if (id == null){
            departmentService.add(department);
        }else {
            departmentService.update(department);
        }
        return AjaxResult.me().success();
    }

    @Delete("/{id}")
    public AjaxResult delete(@PathVariable Long id){
        departmentService.delete(id);
        return AjaxResult.me().success();
    }

}
